package cate.game.role.farm.forbidden;

import cate.common.table.d.GDForbidden;
import cp.solution.util.time.TimeSpanCheck;
import cate.game.role.Role;
import cate.game.role.RoleDependent;
import com.fasterxml.jackson.annotation.JsonIgnore;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;
import org.springframework.data.annotation.Transient;

@NoteClass(value = "种族禁地副本的具体一种副本的记录")
public class ForbiddenPO extends RoleDependent {
    @NoteField("圣殿类型")
    public int roomId;
    @NoteField("已经通关数量")
    public int roundPass;
    @NoteField("历史最大通关数")
    public int passMax = 0;
    @NoteField("积分")
    public int score = 0;

    public ForbiddenPO() {
    }

    @Override
    public void initialize(Role role) {
        super.initialize(role);

    }

    /**
     * 重置数据（因为跨周）
     */
    @Transient
    @JsonIgnore
    public void reset() {
        roundPass = 0;
        score = 0;
    }

    /**
     * 防止跨周时数据异常
     *
     * @param combatNumPass
     */
    public void setPassSafe(int combatNumPass) {
        if (combatNumPass != this.roundPass + 1) {
            return;
        }
        this.roundPass++;
        if (this.roundPass > passMax) {
            passMax = combatNumPass;
        }
    }

    public void addScore(int score,long time) {
        this.score += score;

        boolean spanWeek = TimeSpanCheck.spanWeek(time);
        // 恰好跨周的话不记录排行榜
        if (!spanWeek) {
            // 记录排行榜
//                role.getGame().rank.forbidden.record(role, tpl.roomId, po(role).getCombatNumPassTotal(), role.getBase().power);
            role.getGame().rank.forbidden.record(role, GDForbidden.RANK_ALL_TYPE, role.getFarm().forbidden.getScoreTotal(), System.currentTimeMillis());
//                role.getGame().rank.forbidden.record(role, tpl.roomId, po(role).getFb(fb.roomId).roundPass, System.currentTimeMillis());
        }
    }
}
